package com.example.script.admin.enums;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * @author CuiZhaolong
 * @DATE 2022/2/18
 */
@ApiModel("分页返回对象")
public class ResultPage<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty("返回数据")
    protected T data;
    @ApiModelProperty(
            value = "第几页",
            required = true
    )
    private int pageIndex;
    @ApiModelProperty(
            value = "每页条数",
            required = true
    )
    private int pageSize;
    @ApiModelProperty("总共页数")
    private int totalPages;
    @ApiModelProperty("总共条数")
    private long totalElements;

    ResultPage(T data, int pageIndex, int pageSize, int totalPages, long totalElements) {
        this.data = data;
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.totalPages = totalPages;
        this.totalElements = totalElements;
    }

    public static <T> ResultPage.ResultPageBuilder<T> builder() {
        return new ResultPage.ResultPageBuilder();
    }

    public T getData() {
        return this.data;
    }

    public int getPageIndex() {
        return this.pageIndex;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public int getTotalPages() {
        return this.totalPages;
    }

    public long getTotalElements() {
        return this.totalElements;
    }

    public static class ResultPageBuilder<T> {
        private T data;
        private int pageIndex;
        private int pageSize;
        private int totalPages;
        private long totalElements;

        ResultPageBuilder() {
        }

        public ResultPage.ResultPageBuilder<T> data(T data) {
            this.data = data;
            return this;
        }

        public ResultPage.ResultPageBuilder<T> pageIndex(int pageIndex) {
            this.pageIndex = pageIndex;
            return this;
        }

        public ResultPage.ResultPageBuilder<T> pageSize(int pageSize) {
            this.pageSize = pageSize;
            return this;
        }

        public ResultPage.ResultPageBuilder<T> totalPages(int totalPages) {
            this.totalPages = totalPages;
            return this;
        }

        public ResultPage.ResultPageBuilder<T> totalElements(long totalElements) {
            this.totalElements = totalElements;
            return this;
        }

        public ResultPage<T> build() {
            return new ResultPage(this.data, this.pageIndex, this.pageSize, this.totalPages, this.totalElements);
        }

        public String toString() {
            return "ResultPage.ResultPageBuilder(data=" + this.data + ", pageIndex=" + this.pageIndex + ", pageSize=" + this.pageSize + ", totalPages=" + this.totalPages + ", totalElements=" + this.totalElements + ")";
        }
    }
}
